package com.mp.chart.utils;

import android.content.Context;
import android.widget.TextView;

import com.android.model.info.LocalSp;


/**
 * 价格工具类
 * Created by TenFace on 2017/7/25.
 */

public class PriceColorUtil {

    private static int beginColor = 1;
    private static int endColor = 1;
    private static int defaultColor = 1;

    /***
     * 与昨收比
     * @param view
     * @param price
     * @param lastClose
     */
    public static void setPriceColor(Context context, TextView view, double price, double lastClose) {
        try {
            beginColor = LocalSp.getInstance(context).getBeginColor();
            endColor = LocalSp.getInstance(context).getEndColor();
            defaultColor = LocalSp.getInstance(context).getDefaultColor();
            if (price > lastClose) {
                view.setTextColor(beginColor);//红
            } else if (price < lastClose) {
                view.setTextColor(endColor);//绿
            } else {
                view.setTextColor(defaultColor);//灰
            }
            view.setText(StringUtils.doubleToDoubleString(price));
        } catch (Exception e) {
            view.setText("--");
            view.setTextColor(defaultColor);//灰
        }
    }

    public static int getPriceColor(Context context, double price, double lastClose) {
        try {
            if (price > lastClose) {
                return beginColor;//红
            } else if (price < lastClose) {
                return endColor;//绿
            } else {
                return defaultColor;//灰
            }
        } catch (Exception e) {
            return defaultColor;//灰
        }
    }

    /***
     * 与0比
     * @param view
     * @param percent
     */
    public static void setPercentColor(Context context, TextView view, double percent) {
        try {
            if (percent > 0) {
                view.setTextColor(beginColor);//红
            } else if (percent < 0) {
                view.setTextColor(endColor);//绿
            } else {
                view.setTextColor(defaultColor);//灰
            }
        } catch (Exception e) {
            e.printStackTrace();
            view.setText("--");
            view.setTextColor(defaultColor);//灰
        }
    }

    /***
     * 与0比
     * @param percent
     */
    public static int getPercentColor(Context context, double percent) {
        try {
            if (percent > 0) {
                return beginColor;//红
            } else if (percent < 0) {
                return endColor;//绿
            } else {
                return defaultColor;//灰
            }
        } catch (Exception e) {
            e.printStackTrace();
            return defaultColor;//灰

        }
    }
}
